//
//  MHAskItemViewModel.m
//  MiaoCircle
//
//  Created by 许正荣 on 2018/4/28.
//  Copyright © 2018年 acgera. All rights reserved.
//

#import "MHAskItemViewModel.h"
#import "MHComposeViewModel.h"
#import "MHMomentViewModel.h"
#import "MHEditMemberInfoViewModel.h"

@implementation MHAskItemViewModel


- (instancetype)initWithModel:(MHCircleMember *)model{
   if (self = [super init]) {
        self.model = model;
        
        self.cellHeight = 60;
        
    }
    return self;
}

-(instancetype)initWithServices:(id<MHViewModelServices>)services params:(NSDictionary *)params
{
    if (self = [super initWithServices:services params:params]) {
        self.model = params[MHViewModelUtilKey];
    }

    return self;
}

-(void)initialize
{
    [super initialize];
    @weakify(self);
    self.askCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(NSMutableArray *array) {
        @strongify(self);
        //提问类型
        MHComposeViewModel * model = [[MHComposeViewModel alloc] initWithServices:self.services params:@{@"MHCirclComposeType":@(MHCirclComposeTypeAsk),MHViewModelUtilKey:self.info,@"MHViewModelPhotoes":array}];
        self.selectAsserts = self.selectAsserts;
        model.member = self.model;
        model.model = self.info;
        [self.services presentViewModel:model animated:YES completion:nil];
        return [RACSignal empty];
        
    }];
    
    self.answerCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input) {
        @strongify(self);
        
        NSString *title = @"";
        if (self.isAll) {
            title = [NSString stringWithFormat:@"我的提问(%d)",self.model.askCount];
        }else
        {
            title = [NSString stringWithFormat:@"TA的回答(%d)",self.model.answerCount];
        }
        
        
        MHMomentViewModel * model = [[MHMomentViewModel alloc] initWithServices:self.services params:@{MHViewModelIDKey:@(self.info.autoId),MHViewModelTitleKey:title}];
        if (self.isAll) {
             model.isAskList = YES;
        }else
        {
             model.isAnserList = YES;
        }
       
        model.userId = (int) self.model.userId;
        [self.services pushViewModel:model animated:YES];
        return [RACSignal empty];
    }];
    
    self.editInfoCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input) {
        @strongify(self);
        MHEditMemberInfoViewModel * model = [[MHEditMemberInfoViewModel alloc] initWithServices:self.services params:@{MHViewModelUtilKey: input }];
        [self.services pushViewModel:model animated:YES];
        return [RACSignal empty];
    }];
    
}


@end
